<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/23
 * Time: 10:44
 */

namespace app\common\controller;
use think\Controller;
use think\Db;
use think\Loader;

class AdminBase extends Controller
{
    protected $_config;
    protected $_juri;
    public function __construct()
    {
        parent::__construct();
        $this->checkAdmin();
        $this->checkJurisdiction();
    }

    protected function checkAdmin()
    {
        if (!cookie('admin'))
        {
            $this->redirect('admin/login/index');
        }
    }

    protected function checkJurisdiction()
    {
        $adminInfo = Db::name('admin')
            ->field('level')
            ->where('id', cookie('admin'))
            ->find();
        $jurisdiction = Db::name('admin_role')
            ->field('jurisdiction, nav')
            ->where('id', $adminInfo['level'])
            ->find();
        $navGroup = Db::name('admin_nav_group')
            ->field('id, title')
            ->order('sort asc')
            ->select();
        $juri        = json_decode($jurisdiction['jurisdiction'], true);
        $this->_juri = $juri;
        $this->assign('navGroup', $navGroup);
        $this->assign('navList', json_decode($jurisdiction['nav'], true));
        $this->assign('_juri', json_decode($jurisdiction['jurisdiction'], true));
    }
}